const validate = require('../../utils/validate')
const common = require('../../utils/common')
const { getShopStaticSaleCount } = require('../../services/stores')

Page({
  data: {
    type: '1',
    myShopStatics: {},
    dataList: [],
    loaded: false,
    tabList: [
      { name: '今日', value: '1' },
      { name: '本月', value: '2' },
      { name: '累计', value: '3' },
    ],
  },
  onLoad: function () {
    this.getDataList()
  },
  tabChange: function (e) {
    const { index } = e.currentTarget.dataset;
    const item = this.data.tabList[index];
    this.typeChange(item.value)
  },

  typeChange: function (type) {
    this.setData({
      type,
    }, this.getDataList)
  },
  getDataList: function (options) {
    const params = { type: this.data.type, ...options }
    getShopStaticSaleCount(params).then(res => {
      this.setData({
        dataList: res.data.shopStaticsList,
        myShopStatics: res.data.myShopStatics
      })
      this.setData({
        loaded: true
      })
    }).catch(err => {
      common.log(err)
    })
  },
})